package br.com.upper.business;

import java.util.List;

import br.com.upper.entity.InstanceType;
import br.com.upper.entity.TestConfiguration;
import br.com.upper.entity.TestInstanceResult;
import br.com.upper.entity.TestResult;
import br.com.upper.entity.Transaction;
import br.com.upper.util.TxProxy;

public class Facade implements IFacade {

	private static Facade instance;
	
	private ITestConfigurationBO testConfigurationBO;
	private IInstanceTypeBO instanceTypeBO;
	private ITransactionBO transactionBO;
	private ITestResultBO testResultBO;
	private ITestInstanceResultBO testInstanceResultBO;
	
	private Facade() {
		this.testConfigurationBO = (ITestConfigurationBO) TxProxy.newInstance(new TestConfigurationBO());
		this.instanceTypeBO = (IInstanceTypeBO) TxProxy.newInstance(new InstanceTypeBO());
		this.transactionBO = (ITransactionBO) TxProxy.newInstance(new TransactionBO());
		this.testResultBO = (ITestResultBO) TxProxy.newInstance(new TestResultBO());
		this.testInstanceResultBO = (ITestInstanceResultBO) TxProxy.newInstance(new TestInstanceResultBO());
	}
	
	public static Facade getInstance() {
		if(instance == null) {
			instance = new Facade();
		}
		return instance;
	}
	
	public void saveInstanceType(InstanceType obj) {
		this.instanceTypeBO.save(obj);
	}
	
	public void saveTestConfiguration(TestConfiguration obj) {
		this.testConfigurationBO.save(obj);
	}
	
	public List<InstanceType> findAllInstanceType() {
		return this.instanceTypeBO.findAll();
	}
	
	public TestConfiguration getTestConfiguration() {
		TestConfiguration testConfiguration = null;
		List<TestConfiguration> list = this.testConfigurationBO.findAll();
		if(list != null && list.size() > 0) {
			testConfiguration = list.get(0);
		}
		return testConfiguration;
	}
	
	public static void main(String arg[]) {
		Facade.getInstance().getTestConfiguration();
	}

	public void deleteAllTransactions() {
		this.transactionBO.deleteAll();		
	}

	public void saveTransaction(Transaction obj) {
		this.transactionBO.save(obj);
	}

	@Override
	public void saveTestResult(TestResult obj) {
		this.testResultBO.save(obj);		
	}

	@Override
	public List<TestResult> findAllTestResult() {
		return this.testResultBO.findAll();
	}
	
	@Override
	public void saveTestInstanceResult(TestInstanceResult obj) {
		this.testInstanceResultBO.save(obj);		
	}

	@Override
	public List<TestInstanceResult> findAllTestInstanceResult() {
		return this.testInstanceResultBO.findAll();
	}
	
	@Override
	public List<InstanceType> findOtherInstancesTest() {
		return this.instanceTypeBO.findOtherInstancesTest();
	}
	
}
